/*import java.awt.Color;
import java.text.SimpleDateFormat;
import javax.swing.JPanel;


/**
 * Write a description of class FormLearning here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
package amd.ui;

import amd.core.UIListener;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.ArrayList;

public class FrameMain1 extends JFrame {

    private String inputKeyword;
    private UIListener listener;
    //--------------------------------------------
    private Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    private Container container = getContentPane();
    //--------------------------------------------
    //GUI Component
    //--------------------------------------------
    private JPanel topPanel = new JPanel();
    private JPanel bottomPanel = new JPanel();
    private JButton searchButton = new JButton();
    private JButton extractButton = new JButton();
    private JButton uploadButton = new JButton();
    private JButton logButton = new JButton();
    private JButton docButton[] = new JButton[10];
    private JLabel headerLabel = new JLabel();
    private JButton prevButton = new JButton();
    private JButton nextButton = new JButton();
    private JTextField searchTextField = new JTextField();
    private JPanel docRelevanPanel = new JPanel();
    private int page;
    private int maxPage;
    private ArrayList<ArrayList<String>> listDoc;

    /**
     * Constructor for objects of class FormLearning
     */
    public FrameMain1() throws Exception {
        super("AMD LSA");
        listener = new UIListener(this);
        page = 0;
        inputKeyword = "";
        listDoc = new ArrayList<ArrayList<String>>();

        initComponents();
        setVisible(true);
    }

    public void initComponents() {
        //setBorder( BorderFactory.createEtchedBorder() );
        setSize(600, 780);
        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        setLocation(0, 0);
        //init Panel
        topPanel.setLayout(null);
        topPanel.setLocation(0, 0);
        topPanel.setSize(600, 200);
        topPanel.setBorder(BorderFactory.createEtchedBorder());

        bottomPanel.setLayout(new CardLayout());
        bottomPanel.setLocation(0, 200);
        bottomPanel.setSize(600, 600);
        bottomPanel.setBorder(BorderFactory.createEtchedBorder());


        docRelevanPanel.setLocation(0, 200);
        docRelevanPanel.setLayout(null);
        docRelevanPanel.setSize(600, 600);
        docRelevanPanel.setBackground(Color.white);
        docRelevanPanel.setBorder(BorderFactory.createEtchedBorder());


        //updateComponentDocRelevan();
        componentsTopPanel();

        container.setLayout(null);
        container.add(topPanel);
        container.add(bottomPanel);

        searchTextField.addFocusListener(new java.awt.event.FocusAdapter() {

            @Override
            public void focusLost(java.awt.event.FocusEvent evt) {
                inputKeyword = searchTextField.getText();
            }
        });
        searchTextField.addKeyListener(new java.awt.event.KeyAdapter() {

            @Override
            public void keyReleased(java.awt.event.KeyEvent evt) {
                char c = (char) evt.getKeyCode();
                if (c == KeyEvent.VK_ENTER) {
                    inputKeyword = searchTextField.getText();
                    searchDocument(inputKeyword);
                }
            }
        });


    }
    //--------------------------------------------------------------------------

    public void componentsTopPanel() {

        //init search button
        searchButton = GUISetting.getButton("Search", "search", buttonListener);
        GUISetting.setButton(searchButton, new Rectangle(300, 50, 100, 22), "");

        //init search button
        extractButton = GUISetting.getButton("Extract", "extract", buttonListener);
        GUISetting.setButton(extractButton, new Rectangle(300, 100, 100, 22), "");

        uploadButton = GUISetting.getButton("Upload", "upload", buttonListener);
        GUISetting.setButton(uploadButton, new Rectangle(450, 50, 100, 22), "");

        logButton = GUISetting.getButton("View Log", "viewLog", buttonListener);
        GUISetting.setButton(logButton, new Rectangle(450, 100, 100, 22), "");
        //text field search
        GUISetting.setTextField(searchTextField, new Rectangle(10, 50, 275, 22), "searchField", textFieldListener);


        //proses add ke panel top
        topPanel.add(searchButton);
        topPanel.add(extractButton);
        topPanel.add(uploadButton);
        topPanel.add(logButton);
        topPanel.add(searchTextField);
    }

    public void updateComponentDocRelevan() {
        int x = 10, y = 10;

        int arrSize = listDoc.get(0).size();

        if (arrSize > 0) {
            headerLabel = GUISetting.getLabel("Hasil Pencarian Berdasarkan Keyword");//label input
            
            for (int i = 0; i < arrSize; i++) {
                docButton[i] = GUISetting.getButton(listDoc.get(1).get(i), listDoc.get(0).get(i), buttonListener);
            //System.out.println(listDoc.get(0).get(i) + " " + listDoc.get(1).get(i));
            }
            prevButton = GUISetting.getButton("Prev", "prev", buttonListener);
            nextButton = GUISetting.getButton("Next", "next", buttonListener);

            y = y + 25;
            for (int i = 0; i < arrSize; i++) {
                GUISetting.setButton(docButton[i], new Rectangle(x, y, 590, 22), "");
                y = y + 40;
            }
            for (int i = 0; i < arrSize; i++) {
                docButton[i].setBorder(null);
                docButton[i].setBackground(Color.white);
            }
            GUISetting.setButton(prevButton, new Rectangle(x, y + 25, 100, 22), "");
            GUISetting.setButton(nextButton, new Rectangle(x + 150, y + 25, 100, 22), "");

            docRelevanPanel.add(prevButton);
            docRelevanPanel.add(nextButton);

            for (int i = 0; i < arrSize; i++) {
                docRelevanPanel.add(docButton[i]);
            }
        }
        else {
            headerLabel = GUISetting.getLabel("Tidak ditemukan dokumen dengan keyword \'" + inputKeyword + "\'");//label input
        }
        
        GUISetting.setLabel(headerLabel, new Rectangle(10, 10, 590, 22), "");//set label input
        docRelevanPanel.add(headerLabel);
    }

    public void updatePanelBottom() {
        container.remove(bottomPanel);
        container.add(docRelevanPanel);
        repaint();
    }
    //--------------------------------------------------------------------------
    //Action Listener untuk textFiled
    //--------------------------------------------------------------------------
    ActionListener textFieldListener = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String command = e.getActionCommand();
        }
    };
    //--------------------------------------------------------------------------
    //Action Listener untuk Button
    //--------------------------------------------------------------------------
    ActionListener buttonListener = new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            String command = e.getActionCommand();
            if (command.equals("search")) {
                searchDocument(inputKeyword);
            //updatePanelBottom();
            } else if (command.equals("extract")) {
                listener.ekstrakDokumen();
            } else if (command.equals("upload")) {
                listener.uploadDocument();
            } else if (command.equals("viewLog")) {
                listener.viewLog();
            } else if (command.equals("prev")) {
                if (page > 0) {
                    page = page--;
                }
            } else if (command.equals("next")) {
                if (page < maxPage) {
                    page = page++;
                }

            }
        }
    };

    public void setTextDoc() {
        //Array List untuk memasukkan list dokumen yang ada
        for (int i = 0; i < 10; i++) {
            docButton[i].setText("");
        }

    }

    private void searchDocument(String keyword) {
        if (!keyword.isEmpty()) {
            listDoc = listener.searchDocumentByKeyword(inputKeyword, page);
            //maxPage = listener.getMaxPage();
//            if(!listDoc.isEmpty()){
                updateComponentDocRelevan();
                updatePanelBottom();
//            }
//            else{
//                System.out.println("aneeehhhhh");
//            }

        } else {
            listDoc.clear();
            JOptionPane.showMessageDialog(this, "Keyword Kosong. \nHarap isi keyword dari dokumen yang akan dicari",
                    "Cari Dokumen", JOptionPane.WARNING_MESSAGE, null);
        }
    }

    //--------------------------------------------------------------------------
    //close Windows
    //--------------------------------------------------------------------------
    public void closeWindow() {
        dispose();
    }
}


        
